package Format;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author MJS
 * @Date 2021/8/5 11:57
 * @Description
 */
public class ConversionFormat {

    public static void main(String[] args) {

     /*   Parent parent = new Parent();
        parent.setAddress("河北省");
        parent.setAge("18");
        parent.setName("张三");
        parent.setSalary(new BigDecimal("9999.99"));
        parent.setSex("男");
        //将对象转换成字符串
        String s = JSON.toJSONString(parent);
        System.out.println(s);
        //将字符串转换成json对象在转换为对象
        JSONObject jsonObject = JSONObject.parseObject(s);
        Parent parent1 = jsonObject.toJavaObject(parent.getClass());
        System.out.println(parent1.getAddress());
        //String转换为List

        String gameString = "199,99,243,34,52,57,193,277,194,284,275,270,274,54,238,259,225,262,32,53,31,196,33,286,246,285,94,200,276,269,242,271,40,272,278,251,5,288,11,283,245,253,58,241,282,197,237,93,55,198,273,235,250,4,287,293,291,290,298,292,294,297,305,257,309,302,304,300,318,301,307,310,311,312,303,295,316,317,324,327,321,254";
        List<String> gameids = java.util.Arrays.asList(gameString.split(","));
        System.out.println(gameids);*/

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("auditUserId",1);
        jsonObject1.put("auditUserName","张三");
        jsonObject1.put("remark","第一次");
        jsonObject1.put("auditTime",String.format("%tF %<tT",new Date()));
        System.out.println(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("auditUserId",2);
        jsonObject2.put("auditUserName","李四");
        jsonObject2.put("remark","第二次");
        jsonObject2.put("auditTime",String.format("%tF %<tT",new Date()));
        System.out.println(jsonObject2);

        JSONArray arr = new JSONArray();
        arr.add(jsonObject1);
        arr.add(jsonObject2);
        System.out.println(arr);

       //JSONArray->String
        System.out.println(arr.toJSONString());

        arr= JSON.parseArray(arr.toJSONString());
        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("auditUserId",3);
        jsonObject3.put("auditUserName","王五");
        jsonObject3.put("remark","第三次");
        jsonObject3.put("auditTime",String.format("%tF %<tT",new Date()));
        arr.add(jsonObject3);
        System.out.println(arr);

    }

}
